import { fileURLToPath, URL } from 'node:url'
import path from "path";
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
//解决vue3中setup无法直接命名组件名称的问题
import VueSetupExtend from 'vite-plugin-vue-setup-extend'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import vueJsx from '@vitejs/plugin-vue-jsx'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueJsx(),
    VueSetupExtend(),
    createSvgIconsPlugin({
      // 指定 SVG图标 保存的文件夹路径
      iconDirs: [path.resolve(process.cwd(), 'src/components/formDesigner/icons/svg')],
      // 指定 使用svg图标的格式
      symbolId: 'icon-[dir]-[name]',
    })
  ],
  build: {
    assetsDir: 'static',
    minify: 'terser',
    brotliSize: false,
    // 消除打包大小超过500kb警告
    chunkSizeWarningLimit: 2000,
    terserOptions: {
      compress: {
        drop_console: true,
        drop_debugger: true
      }
    }
  },
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    },
    extensions: ['.js', '.ts', '.jsx', '.tsx', '.json', '.vue', '.mjs']
  },
  css: {
    preprocessorOptions: {
      scss: {
        api: 'modern-compiler',
        silenceDeprecations: ['legacy-js-api'],
        javascriptEnabled: true,
        additionalData: `
          @use "@/assets/styles/globalVar.scss" as *;
          @use "@/assets/styles/globalMixin.scss" as *;
        `,
      },
    },
    // css sass  charset 报错
    postcss: {
      plugins: [
          {
            postcssPlugin: 'internal:charset-removal',
            AtRule: {
              charset: (atRule) => {
                if (atRule.name === 'charset') {
                  atRule.remove();
                }
              }
            }
          }
      ],
    }
  },
  optimizeDeps: {
    include: ['element-plus/es/locale/lang/zh-cn',
     'bpmn-js/lib/Modeler',
     'bpmn-js-token-simulation'
    ]
  }
})
